# coding=utf-8
from django import template
from django.utils.safestring import mark_safe

__author__ = 'czq'
register = template.Library()

def getClassWxjHtml(classModel):
        #raise  Exception,classModel.parent==None
        if classModel==None:
            return ''
        html=''
        active=True
        while True:
            if active:
                html=getClassHtml(classModel,'class="active"')+html
                active=False
            else:

                html=getClassHtml(classModel)+html
            if classModel.parent==None:
                #html=getClassHtml(classModel)+html
                break
            else:
                classModel=classModel.parent
        return html
def getClassHtml(model,className=''):

    result="<li %s><a href='/BbsTheme/bbsTheme_list-%s/'>%s</a></li>"%(className,model.id,model.name)
    return mark_safe(result)
    #return '<li><a href="#">Home</a></li>'

def getClassTopMenuHtml(value):
    #return value
    return mark_safe(getClassWxjHtml(value))
register.filter('getClassTopMenuHtml', getClassTopMenuHtml)

#class TestNode(template.Node):
#    def __init__(self,list,value,text,selectName):
#        self.list=list
#        self.value=value
#        self.text=text
#        self.selectName=selectName;
#    def render(self, context):
#        return "aa"
#def getClassTopMenuHtml(parser, token):
#    try:
#        tag_name,classModel  = token.split_contents()
#    except:
#        raise template.TemplateSyntaxError,u" 标签语法错误"
#    return TestNode(list,classModel)
#register.tag('getClassTopMenuHtml', getClassTopMenuHtml)

#最新文章
@register.inclusion_tag('tags/dummy.html')
def class_theme_childclass(classChild, template="BbsTheme/tags/class_theme_childclass.html"):
    return {
            "template": template,
            'classChild':classChild,
            }